/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

package com.qdu.dao.impl;
import com.qdu.dao.JoinDao;
import com.qdu.entity.Join;
import com.qdu.util.DatabaseUtil;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

/**
 *
 * @author Daniel
 */
public class JoinDaoImpl extends BaseDaoImpl implements JoinDao{

    @Override
    public int insert(Join j) {
    return executeUpdate("insert into [Join] values(?,?,?)", j.getUno(),j.getUname(),j.getPno()); 
  
    }

    @Override
    public int exit(int Uno) {
        return executeUpdate("delete [Join] where Uno=?", Uno);
    }

    @Override
    public List<Join> getUsersByPno(int Pno) {
        
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        List<Join> list = new ArrayList<>();
        
        try {
            con = DatabaseUtil.getConnection();
            ps = con.prepareStatement("select * from [Join] where Pno=?");
            ps.setInt(1, Pno);
            rs = ps.executeQuery();
            while (rs.next()) {
                list.add(new Join(rs.getInt(1), rs.getString(2), rs.getInt(3)));
            }
        } catch (Exception e) {
            e.printStackTrace();
        } finally {
            DatabaseUtil.close(rs, ps, con);
        }
        return list;
    }
 
}






